from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-13 14:32:02.811063
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 13, Jan, 2021
Time: 14:32:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.0375
Nobs: 170.000 HQIC: -46.0240
Log likelihood: 1888.33 FPE: 5.24802e-21
AIC: -46.6977 Det(Omega_mle): 3.13750e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.449014 0.151134 2.971 0.003
L1.Burgenland 0.142557 0.077682 1.835 0.066
L1.Kärnten -0.235537 0.063024 -3.737 0.000
L1.Niederösterreich 0.125024 0.180327 0.693 0.488
L1.Oberösterreich 0.239809 0.154139 1.556 0.120
L1.Salzburg 0.183789 0.081585 2.253 0.024
L1.Steiermark 0.077598 0.111444 0.696 0.486
L1.Tirol 0.153622 0.073915 2.078 0.038
L1.Vorarlberg 0.015438 0.070484 0.219 0.827
L1.Wien -0.136456 0.149681 -0.912 0.362
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.527063 0.193496 2.724 0.006
L1.Burgenland 0.015253 0.099457 0.153 0.878
L1.Kärnten 0.370641 0.080689 4.593 0.000
L1.Niederösterreich 0.128568 0.230872 0.557 0.578
L1.Oberösterreich -0.174958 0.197344 -0.887 0.375
L1.Salzburg 0.176488 0.104453 1.690 0.091
L1.Steiermark 0.238022 0.142682 1.668 0.095
L1.Tirol 0.144252 0.094633 1.524 0.127
L1.Vorarlberg 0.189427 0.090240 2.099 0.036
L1.Wien -0.599822 0.191636 -3.130 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.304626 0.066705 4.567 0.000
L1.Burgenland 0.105308 0.034286 3.071 0.002
L1.Kärnten -0.024614 0.027817 -0.885 0.376
L1.Niederösterreich 0.061691 0.079590 0.775 0.438
L1.Oberösterreich 0.282757 0.068032 4.156 0.000
L1.Salzburg -0.000776 0.036009 -0.022 0.983
L1.Steiermark -0.021628 0.049188 -0.440 0.660
L1.Tirol 0.097008 0.032624 2.974 0.003
L1.Vorarlberg 0.125466 0.031109 4.033 0.000
L1.Wien 0.076578 0.066064 1.159 0.246
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208700 0.078596 2.655 0.008
L1.Burgenland -0.005708 0.040398 -0.141 0.888
L1.Kärnten 0.024707 0.032775 0.754 0.451
L1.Niederösterreich 0.030473 0.093777 0.325 0.745
L1.Oberösterreich 0.391743 0.080159 4.887 0.000
L1.Salzburg 0.092419 0.042427 2.178 0.029
L1.Steiermark 0.182514 0.057956 3.149 0.002
L1.Tirol 0.042720 0.038439 1.111 0.266
L1.Vorarlberg 0.102149 0.036655 2.787 0.005
L1.Wien -0.071909 0.077840 -0.924 0.356
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.569167 0.157038 3.624 0.000
L1.Burgenland 0.080365 0.080717 0.996 0.319
L1.Kärnten 0.005049 0.065486 0.077 0.939
L1.Niederösterreich -0.026011 0.187371 -0.139 0.890
L1.Oberösterreich 0.137208 0.160161 0.857 0.392
L1.Salzburg 0.046933 0.084772 0.554 0.580
L1.Steiermark 0.111369 0.115798 0.962 0.336
L1.Tirol 0.222707 0.076803 2.900 0.004
L1.Vorarlberg 0.016281 0.073237 0.222 0.824
L1.Wien -0.147807 0.155528 -0.950 0.342
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170388 0.111138 1.533 0.125
L1.Burgenland -0.023136 0.057125 -0.405 0.685
L1.Kärnten -0.012690 0.046345 -0.274 0.784
L1.Niederösterreich 0.175515 0.132605 1.324 0.186
L1.Oberösterreich 0.380245 0.113348 3.355 0.001
L1.Salzburg -0.033388 0.059994 -0.557 0.578
L1.Steiermark -0.048762 0.081952 -0.595 0.552
L1.Tirol 0.195608 0.054354 3.599 0.000
L1.Vorarlberg 0.046811 0.051831 0.903 0.366
L1.Wien 0.157424 0.110069 1.430 0.153
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233768 0.140092 1.669 0.095
L1.Burgenland 0.062852 0.072007 0.873 0.383
L1.Kärnten -0.050025 0.058419 -0.856 0.392
L1.Niederösterreich -0.034413 0.167152 -0.206 0.837
L1.Oberösterreich -0.094095 0.142878 -0.659 0.510
L1.Salzburg 0.024449 0.075624 0.323 0.746
L1.Steiermark 0.371041 0.103302 3.592 0.000
L1.Tirol 0.513533 0.068515 7.495 0.000
L1.Vorarlberg 0.192320 0.065334 2.944 0.003
L1.Wien -0.216791 0.138745 -1.563 0.118
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.101888 0.164806 0.618 0.536
L1.Burgenland 0.016663 0.084710 0.197 0.844
L1.Kärnten -0.103700 0.068725 -1.509 0.131
L1.Niederösterreich 0.230507 0.196640 1.172 0.241
L1.Oberösterreich 0.018239 0.168084 0.109 0.914
L1.Salzburg 0.220170 0.088965 2.475 0.013
L1.Steiermark 0.142074 0.121526 1.169 0.242
L1.Tirol 0.097348 0.080602 1.208 0.227
L1.Vorarlberg 0.020664 0.076860 0.269 0.788
L1.Wien 0.264115 0.163221 1.618 0.106
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595061 0.089381 6.658 0.000
L1.Burgenland -0.022092 0.045941 -0.481 0.631
L1.Kärnten -0.001642 0.037272 -0.044 0.965
L1.Niederösterreich -0.016942 0.106645 -0.159 0.874
L1.Oberösterreich 0.276091 0.091158 3.029 0.002
L1.Salzburg 0.008906 0.048249 0.185 0.854
L1.Steiermark 0.001454 0.065908 0.022 0.982
L1.Tirol 0.078888 0.043713 1.805 0.071
L1.Vorarlberg 0.169444 0.041684 4.065 0.000
L1.Wien -0.083729 0.088521 -0.946 0.344
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149735 0.000617 0.216449 0.251395 0.064944 0.094338 -0.063103 0.158676
Kärnten 0.149735 1.000000 0.000239 0.190622 0.154797 -0.131664 0.161580 0.030458 0.303532
Niederösterreich 0.000617 0.000239 1.000000 0.283256 0.085496 0.215215 0.096488 0.060725 0.353259
Oberösterreich 0.216449 0.190622 0.283256 1.000000 0.294366 0.312452 0.085502 0.085471 0.120341
Salzburg 0.251395 0.154797 0.085496 0.294366 1.000000 0.153781 0.071347 0.079380 -0.022808
Steiermark 0.064944 -0.131664 0.215215 0.312452 0.153781 1.000000 0.098436 0.089399 -0.121064
Tirol 0.094338 0.161580 0.096488 0.085502 0.071347 0.098436 1.000000 0.147772 0.131013
Vorarlberg -0.063103 0.030458 0.060725 0.085471 0.079380 0.089399 0.147772 1.000000 0.096952
Wien 0.158676 0.303532 0.353259 0.120341 -0.022808 -0.121064 0.131013 0.096952 1.000000